package com.bookmarket.service.impl;

import com.bookmarket.dao.LQModuleMapper;
import com.bookmarket.entity.Book;
import com.bookmarket.entity.Module;
import com.bookmarket.entity.Picture;
import com.bookmarket.service.LQModuleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("modelService")
public class LQModuleServiceImpl implements LQModuleService {

    @Resource
    private LQModuleMapper moduleMapper;

    @Override
    public Page queryModuleByPage(Module module, Date start, Date end,int pageIndex,int pageSize) {
        Page page = PageHelper.startPage(pageIndex,pageSize);
        List<Module> list = moduleMapper.queryModuleByPage(module,start,end);
        return page;
    }

    @Override
    public Page queryModule() {
        Page page = PageHelper.startPage(0,8);
        List<Module> list = moduleMapper.queryModule();
        return page;
    }

    @Override
    public void delModule(int id) {
        moduleMapper.delModule(id);
        moduleMapper.delPicture(id);
    }

    @Override
    public Module queryOneModule(int id) {
        return moduleMapper.queryOneModule(id);
    }

    @Override
    public void modModule(Module module) {
        moduleMapper.modModule(module);
    }

    @Override
    public void useModule(int id) {
        moduleMapper.useModule(id);
    }

    @Override
    public void badModule(int id) {
        moduleMapper.badModule(id);
    }

    @Override
    public List<Book> queryBook(int id,String useModel) {
        Map map = new HashMap();
        map.put("id",id);
        map.put("useModel",useModel);
        return moduleMapper.queryBook(map);
    }

    @Override
    public List<Picture> queryPicture(int moduleId) {
        Map map = new HashMap();
        map.put("id",moduleId);
        return moduleMapper.queryPicture(map);
    }

    @Override
    public int addModule(Module module) {
        return moduleMapper.addModule(module);
    }

    @Override
    public int addPicture(int moduleId, String picturePath) {
        Picture picture = new Picture();
        picture.setModuleId(moduleId);
        picture.setPicture(picturePath);
        return moduleMapper.addPicture(picture);
    }

    public void setModuleMapper(LQModuleMapper moduleMapper) {
        this.moduleMapper = moduleMapper;
    }
}
